﻿using Microsoft.PointOfService;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace POS
{
    class PrintingClass
    {
        
        public static float x = 1;
        public static float y = 10;
        public static float width = 300.0F - 120f; // max width I found through trial and error
        public static float height = 0F;

        public static Font drawFontArial12Bold;
        public static Font drawFontArial10Regular;
        public static Font drawFontArial10Bold;
        public static Font drawFontArialRegular;
        public static Font drawFontArialBold;
        public static SolidBrush drawBrush;

        // Set format of string.
        public static StringFormat drawFormatCenter = new StringFormat();
        public static StringFormat drawFormatLeft = new StringFormat();
        public static StringFormat drawFormatRight = new StringFormat();

        static string Receiptno;
        static string Servername;
        static string Tablename;

        static int EmpID;

        public static PosPrinter Printer;

        public static void PrintSetup()
        {
            drawFormatCenter.Alignment = StringAlignment.Center;
            drawFormatLeft.Alignment = StringAlignment.Near;
            drawFormatRight.Alignment = StringAlignment.Far;

            drawFontArial12Bold = new Font("Lekton", 9, FontStyle.Bold);
            drawFontArial10Regular = new Font("Lekton", 7, FontStyle.Regular);
            drawFontArial10Bold = new Font("Lekton", 9, FontStyle.Bold);
            drawFontArialRegular = new Font("Microsoft Sans Serif", 10, FontStyle.Regular);
            drawFontArialBold = new Font("Microsoft Sans Serif", 9, FontStyle.Bold);
            drawBrush = new SolidBrush(Color.Black);
        }

        static void PrintHeader(PrintPageEventArgs e)
        {
            // Draw string to screen.
            string text = "Hayashi Japanese\n Restaurant";
            e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;

            text = "4220 82nd St.";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "Lubbock, Tx 79423";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "Phone (806)792-6868";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "==================================";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

        }

        static void PrintFooter(PrintPageEventArgs e)
        {
            string text = " ";
            e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;
            text = " ";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;
            text = " ";
            e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;
            // Draw string to screen.
            text = "Thank You For Your Business.\n For Comments Please Give Us A Call";
            e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;

            //// Create pen.
            //Pen blackPen = new Pen(Color.Black, 1);
            //// Create rectangle.
            //Rectangle rect = new Rectangle(0, 0, (int)width-120, (int)y + 30);
            //// Draw rectangle to screen.
            //e.Graphics.DrawRectangle(blackPen, rect);

        }

        public static void PrintReceiptForTransaction(string ReceiptNo,string ServerName,string TableName)
        {
            Receiptno = ReceiptNo;
            Servername = ServerName;
            Tablename = TableName;

            //PrintPreviewDialog printDialog = new PrintPreviewDialog();
            //printDialog.Width = 250;
            //printDialog.Height = 500;
            //printDialog.PrintPreviewControl.AutoZoom = false;
            //printDialog.PrintPreviewControl.Zoom = 1.0;

            PrintDialog printDialog = new PrintDialog();


            PrintDocument printDocument = new PrintDocument();

            printDialog.Document = printDocument;
            printDocument.PrintPage += new PrintPageEventHandler(PrintReceiptPage);




            DialogResult result = printDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                printDocument.Print();
            }

            printDocument.Dispose();
        }

        private static void PrintReceiptPage(object sender, PrintPageEventArgs e)
        {

            PrintHeader(e);
            PrintReceiptBody(e);
            //PrintFooter(e);

            x = 2;
            y = 10;
            width = 300.0F - 120f; // max width I found through trial and error
            height = 0F;
        }

        static void PrintReceiptBody(PrintPageEventArgs e)
        {
            string text;

            text = "Date: " + DateTime.Now.ToShortDateString() + "  " + DateTime.Now.ToShortTimeString();
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "Server Name: " + Servername;
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "Tabel Number: " + Tablename;
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "Receipt Number: " + Receiptno;
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "==================================";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "QTY".PadRight(4) + "ITEM NAME".PadRight(24) + "PRICE";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "==================================";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            foreach (DataRow item in DataTableClass.ReceiptData.Rows)
            {
                if (item["ReceiptNo"].ToString().Trim() == Receiptno)
                {
                    string Qty = "1";
                    string Item = item["ReceiptDescription"].ToString().Trim();
                    string price = String.Format("{0:C}", item["ReceiptItemTotal"]);


                    if (Item.Length > 20)
                    {
                        Item = Item.Substring(0, 20) + "...";
                    }


                    e.Graphics.DrawString(Qty.PadRight(4) + Item.PadRight(24) + price, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(Item, drawFontArial10Regular).Height;
                }
            }

            string Item1 = "---------------";
            e.Graphics.DrawString(Item1, drawFontArial10Regular, drawBrush, new RectangleF(x - 10, y, width, height), drawFormatRight);
            y += e.Graphics.MeasureString(Item1, drawFontArial10Regular).Height;


            foreach (DataRow item in DataTableClass.Receipt.Rows)
            {
                if (item["ReceiptNo"].ToString().Trim() == Receiptno)
                {

                    double SubTotal = Convert.ToDouble(item["ReceiptSubTotal"]);
                    double TaxTotal = Convert.ToDouble(item["ReceiptTaxTotal"]);
                    double AutoGrat = Convert.ToDouble(item["ReceiptAutoGrat"]);
                    double BillTotal = SubTotal + TaxTotal + AutoGrat;


                    string Item = (SubTotal).ToString("C");
                    e.Graphics.DrawString("Sub Total: " + Item, drawFontArial10Regular, drawBrush, new RectangleF(x - 10, y, width, height), drawFormatRight);
                    y += e.Graphics.MeasureString(Item, drawFontArial10Regular).Height;

                    Item = (TaxTotal).ToString("C");
                    e.Graphics.DrawString("Tax Total: " + Item, drawFontArial10Regular, drawBrush, new RectangleF(x - 10, y, width, height), drawFormatRight);
                    y += e.Graphics.MeasureString(Item, drawFontArial10Regular).Height;
                    if (AutoGrat != 0)
                    {
                        Item = (AutoGrat).ToString("C");
                        e.Graphics.DrawString("Auto Grat: " + Item, drawFontArial10Regular, drawBrush, new RectangleF(x - 10, y, width, height), drawFormatRight);
                        y += e.Graphics.MeasureString(Item, drawFontArial10Regular).Height;
                    }

                    Item = (TaxTotal).ToString("C");
                    e.Graphics.DrawString("---------------", drawFontArial10Regular, drawBrush, new RectangleF(x - 10, y, width, height), drawFormatRight);
                    y += e.Graphics.MeasureString(Item, drawFontArial10Regular).Height;

                    Item = (BillTotal).ToString("C");
                    e.Graphics.DrawString("Bill Total: " + Item, drawFontArial10Bold, drawBrush, new RectangleF(x - 10, y, width, height), drawFormatRight);
                    y += e.Graphics.MeasureString(Item, drawFontArial10Bold).Height;

                    //text = " ";
                    //e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                    //y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;

                    //Item = (BillTotal).ToString("C");
                    //e.Graphics.DrawString("Grat: ___________", drawFontArial10Bold, drawBrush, new RectangleF(x - 10, y, width, height), drawFormatRight);
                    //y += e.Graphics.MeasureString(Item, drawFontArial10Bold).Height;

                    //text = " ";
                    //e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                    //y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;

                    //Item = (BillTotal).ToString("C");
                    //e.Graphics.DrawString("Total: ___________", drawFontArial10Bold, drawBrush, new RectangleF(x - 10, y, width, height), drawFormatRight);
                    //y += e.Graphics.MeasureString(Item, drawFontArial10Bold).Height;
                }
            }
        }

        public static void PrintEmployeeTimeSheetPage()
        {
            PrintDialog printDialog = new PrintDialog();


            PrintDocument printDocument = new PrintDocument();

            printDialog.Document = printDocument;
            printDocument.PrintPage += new PrintPageEventHandler(printEmployeetimesheet);




            DialogResult result = printDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                printDocument.Print();
            }

            printDocument.Dispose();
        }

        private static void printEmployeetimesheet(object sender, PrintPageEventArgs e)
        {
            PrintHeader(e);
            PrintEmployeeTimeSheet(e);

            x = 2;
            y = 10;
            width = 300.0F - 120f; // max width I found through trial and error
            height = 0F;
        }

        static void PrintEmployeeTimeSheet(PrintPageEventArgs e)
        {
            string text;

            text = "Employee: ".PadRight(15) + "Roger Jenkins";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "Sign In: ".PadRight(15) + "05:28PM Mar 05 Thu";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "Sign Out: ".PadRight(15) + "10:03PM Mar 05 Thu";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "Total Hours: ".PadRight(15) + "4.58";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "==================================";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;
        }

        public static void PrintEmployeeSchedulePage()
        {
            PrintDialog printDialog = new PrintDialog();


            PrintDocument printDocument = new PrintDocument();

            printDialog.Document = printDocument;
            printDocument.PrintPage += new PrintPageEventHandler(printEmployeeSchedule);




            DialogResult result = printDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                printDocument.Print();
                //printDocument.Print();
            }

            printDocument.Dispose();
        }

        private static void printEmployeeSchedule(object sender, PrintPageEventArgs e)
        {
            EmpID = 6577;
            PrintHeader(e);
            PrintEmployeeSchedule(e);

            x = 2;
            y = 10;
            width = 300.0F - 120f; // max width I found through trial and error
            height = 0F;
        }

        static void PrintEmployeeSchedule(PrintPageEventArgs e)
        {
            foreach (DataRow item in DataTableClass.EmployeeSchedule.Rows)
            {
                if (item["EmployeeID"].ToString().Trim() == EmpID.ToString())
                {
                    string text;

                    text = "Week of " + "03/09/2015";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = " ";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = "Mon".PadRight(06) + item["MondayAM"].ToString().Trim().PadRight(15) + item["MondayPM"].ToString().Trim();
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = " ";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = "Tue".PadRight(06) + item["TuesdayAM"].ToString().Trim().PadRight(15) + item["TuesdayPM"].ToString().Trim();
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = " ";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = "Wed".PadRight(06) + item["WednesdayAM"].ToString().Trim().PadRight(15) + item["WednesdayPM"].ToString().Trim();
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = " ";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = "Thu".PadRight(06) + item["ThursdayAM"].ToString().Trim().PadRight(15) + item["ThursdayPM"].ToString().Trim();
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = " ";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = "Fri".PadRight(06) + item["FridayAM"].ToString().Trim().PadRight(15) + item["FridayPM"].ToString().Trim();
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = " ";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = "Sat".PadRight(06) + item["SaturdayAM"].ToString().Trim().PadRight(15) + item["SaturdayPM"].ToString().Trim();
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = " ";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = "Sun".PadRight(06) + item["SundayAM"].ToString().Trim().PadRight(15) + item["SundayPM"].ToString().Trim();
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = " ";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = " ";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = "Total Hours: " + "48.50";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;
                }
            }

        }

        public static void PrintCreditCardSlipPage()
        {

            //PrintDialog printDialog = new PrintDialog();


            PrintDocument printDocument = new PrintDocument();

            //printDialog.Document = printDocument;
            printDocument.PrintPage += new PrintPageEventHandler(printCreditCardSlip);




            //DialogResult result = printDialog.ShowDialog();

            //if (result == DialogResult.OK)
            //{

            printDocument.Print();
            //printDocument.Print();
            //}

            printDocument.Dispose();
        }

        private static void printCreditCardSlip(object sender, PrintPageEventArgs e)
        {
            PrintHeader(e);
            PrintCreditCardSlip(e);

            x = 2;
            y = 10;
            width = 300.0F - 120f; // max width I found through trial and error
            height = 0F;
        }

        static void PrintCreditCardSlip(PrintPageEventArgs e)
        {
            string text;


            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = CreditCardPayment.CardType;
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = CreditCardPayment.MaskedCardNumber;
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = "Entry Method: " + CreditCardPayment.CardMethod;
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = "Invoice #:" + CreditCardPayment.transID;
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = "Appr Code: " + CreditCardPayment.AuthCode;
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = "Amount:".PadRight(20) + CreditCardPayment.PreAuthAmount.ToString("C");
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = "TIP:".PadRight(20) + "__________";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = "Total:".PadRight(20) + "__________";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = "Thank You!";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

        }

        public static void PrintEmployeePayperiodTimeSheet()
        {

            //PrintDialog printDialog = new PrintDialog();


            PrintDocument printDocument = new PrintDocument();

            //printDialog.Document = printDocument;
            printDocument.PrintPage += new PrintPageEventHandler(printEmployeePayperiodTimeSheet);




            //DialogResult result = printDialog.ShowDialog();

            //if (result == DialogResult.OK)
            //{

            printDocument.Print();
            //printDocument.Print();
            //}

            printDocument.Dispose();
        }

        private static void printEmployeePayperiodTimeSheet(object sender, PrintPageEventArgs e)
        {
            PrintHeader(e);
            PrintEmployeePayperiodTimeSheet(e);

            x = 2;
            y = 10;
            width = 300.0F - 120f; // max width I found through trial and error
            height = 0F;
        }

        static void PrintEmployeePayperiodTimeSheet(PrintPageEventArgs e)
        {
            string text;

            foreach (DataRow item in DataTableClass.EmployeeTimeSheet.Rows)
            {
                if (item["EmployeeID"].ToString().Trim() == StaticProperties.ServerID.ToString())
                {
                    text = " ";
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = "DATE".PadRight(11) + "CLOCK IN".PadRight(12) + "CLOCK OUT".PadRight(12) ;
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

                    text = "03/30/2015".PadRight(11) + "3:57:00 PM".PadRight(12) + "11:30:00 PM".PadRight(12);
                    e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
                    y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;
                }
            }
            
        }
    }
}
